﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace smart_test
{
    public partial class ReviewFrm : Form
    {
        public ReviewFrm()
        {
            InitializeComponent();

            Load += new EventHandler(LoadFrm_Load);
            Closed += new EventHandler(LoadFrm_Closed);
        }

        void LoadFrm_Closed(object sender, EventArgs e)
        {
            lvSaveList.LargeImageList.Dispose();
            lvSaveList.Dispose();
        }

        void LoadFrm_Load(object sender, EventArgs e)
        {
            // ImageList 초기화
            ImageList il = new ImageList();
            il.ImageSize = new Size(128, 96);

            lvSaveList.LargeImageList = il;

            // 파일을 파싱한다.
            if (File.Exists(SmartMosaicClientConstants.SAVE_FILE_PATH))
            {
                StreamReader streamReader = File.OpenText(SmartMosaicClientConstants.SAVE_FILE_PATH);

                int imageIndex = 0;

                while (!streamReader.EndOfStream)
                {
                    // 새로운 라인 읽음
                    string line = streamReader.ReadLine();

                    // 데이터를 자른다.
                    string[] lines = line.Split(' ');

                    Bitmap bitmap = new Bitmap(lines[0]);
                    il.Images.Add(bitmap);

                    ListViewItem lvi = new ListViewItem();
                    lvi.Text = lines[1];
                    lvi.ImageIndex = imageIndex++;

                    lvSaveList.Items.Add(lvi);
                }

                streamReader.Close();
            }
        }

       

        private void btReview_Click(object sender, EventArgs e)
        {
            if (lvSaveList.SelectedIndices.Count != 0)
            {
                new ViewFrm(lvSaveList.Items[lvSaveList.SelectedIndices[0]].Text).Show();

                this.Close();
            }
        }

        private void btReview_MouseDown(object sender, MouseEventArgs e)
        {
            btReviewPress.Visible = true;
        }

        private void btReview_MouseUp(object sender, MouseEventArgs e)
        {
            btReviewPress.Visible = false;
        }

        private void btBack_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btBack_MouseDown(object sender, MouseEventArgs e)
        {
            btBackPress.Visible = true;
        }

        private void btBack_MouseUp(object sender, MouseEventArgs e)
        {
            btBackPress.Visible = false;
        }
    }
}